

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Noun Phrase Semantic Segmentation &mdash; NLP Architect by Intel® AI Lab 0.5.2 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script type="text/javascript" src="_static/jquery.js"></script>
        <script type="text/javascript" src="_static/underscore.js"></script>
        <script type="text/javascript" src="_static/doctools.js"></script>
        <script type="text/javascript" src="_static/language_data.js"></script>
        <script type="text/javascript" src="_static/install.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/nlp_arch_theme.css" type="text/css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono" type="text/css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:100,900" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html">
          

          
            
            <img src="_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="quick_start.html">Quick start</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials.html">Jupyter Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="model_zoo.html">Model Zoo</a></li>
</ul>
<p class="caption"><span class="caption-text">NLP/NLU Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="tagging/sequence_tagging.html">Sequence Tagging</a></li>
<li class="toctree-l1"><a class="reference internal" href="sentiment.html">Sentiment Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="bist_parser.html">Dependency Parsing</a></li>
<li class="toctree-l1"><a class="reference internal" href="intent.html">Intent Extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="lm.html">Language Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="information_extraction.html">Information Extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="transformers.html">Transformers</a></li>
<li class="toctree-l1"><a class="reference internal" href="archived/additional.html">Additional Models</a></li>
</ul>
<p class="caption"><span class="caption-text">Optimized Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="quantized_bert.html">Quantized BERT</a></li>
<li class="toctree-l1"><a class="reference internal" href="transformers_distillation.html">Transformers Distillation</a></li>
<li class="toctree-l1"><a class="reference internal" href="sparse_gnmt.html">Sparse Neural Machine Translation</a></li>
</ul>
<p class="caption"><span class="caption-text">Solutions</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="absa_solution.html">Aspect Based Sentiment Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="term_set_expansion.html">Set Expansion</a></li>
<li class="toctree-l1"><a class="reference internal" href="trend_analysis.html">Trend Analysis</a></li>
</ul>
<p class="caption"><span class="caption-text">For Developers</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="generated_api/nlp_architect_api_index.html">nlp_architect API</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer_guide.html">Developer Guide</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">NLP Architect by Intel® AI Lab</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Noun Phrase Semantic Segmentation</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="noun-phrase-semantic-segmentation">
<h1>Noun Phrase Semantic Segmentation<a class="headerlink" href="#noun-phrase-semantic-segmentation" title="Permalink to this headline">¶</a></h1>
<div class="section" id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>Noun-Phrase (NP) is a phrase which has a noun (or pronoun) as its head and zero or more dependent modifiers.
Noun-Phrase is the most frequently occurring phrase type and its inner segmentation is critical for understanding the
semantics of the Noun-Phrase.
The most basic division of the semantic segmentation is to two classes:</p>
<ol class="arabic simple">
<li>Descriptive Structure - a structure where all dependent modifiers are not changing the semantic meaning of the Head.</li>
<li>Collocation Structure - a sequence of words or term that co-occur and change the semantic meaning of the Head.</li>
</ol>
<p>For example:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">fresh</span> <span class="pre">hot</span> <span class="pre">dog</span></code> - hot dog is a collocation, and changes the head (<code class="docutils literal notranslate"><span class="pre">dog</span></code>) semantic meaning.</li>
<li><code class="docutils literal notranslate"><span class="pre">fresh</span> <span class="pre">hot</span> <span class="pre">pizza</span></code> - fresh and hot are descriptions for the pizza.</li>
</ul>
</div>
<div class="section" id="model">
<h2>Model<a class="headerlink" href="#model" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="generated_api/nlp_architect.models.html#nlp_architect.models.np_semantic_segmentation.NpSemanticSegClassifier" title="nlp_architect.models.np_semantic_segmentation.NpSemanticSegClassifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">NpSemanticSegClassifier</span></code></a> model is the first step in the Semantic Segmentation algorithm - the MLP classifier.
The Semantic Segmentation algorithm takes the dependency relations between the Noun-Phrase words, and the MLP classifier inference as the
input - and build a semantic hierarchy that represents the semantic meaning.
The Semantic Segmentation algorithm eventually create a tree where each tier represent a semantic meaning -&gt; if a sequence of words is a
collocation then a collocation tier is created, else the elements are broken down and each one is mapped
to different tier in the tree.</p>
<p>This model trains MLP classifier and inference from such classifier in order to conclude the correct segmentation
for the given NP.</p>
<p>For the examples above the classifier will output 1 (==Collocation) for <code class="docutils literal notranslate"><span class="pre">hot</span> <span class="pre">dog</span></code> and output 0 (== not collocation)
for <code class="docutils literal notranslate"><span class="pre">hot</span> <span class="pre">pizza</span></code>.</p>
</div>
<div class="section" id="files">
<h2>Files<a class="headerlink" href="#files" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><a class="reference internal" href="generated_api/nlp_architect.models.html#nlp_architect.models.np_semantic_segmentation.NpSemanticSegClassifier" title="nlp_architect.models.np_semantic_segmentation.NpSemanticSegClassifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">NpSemanticSegClassifier</span></code></a>: is the MLP classifier model.</li>
<li><strong>examples/np_semantic_segmentation/data.py</strong>: Prepare string data for both <code class="docutils literal notranslate"><span class="pre">train.py</span></code> and <code class="docutils literal notranslate"><span class="pre">inference.py</span></code> using pre-trained word embedding, NLTKCollocations score, Wordnet and wikidata.</li>
<li><strong>examples/np_semantic_segmentation/feature_extraction.py</strong>: contains the feature extraction services</li>
<li><strong>examples/np_semantic_segmentation/train.py</strong>: train the MLP classifier.</li>
<li><strong>examples/np_semantic_segmentation/inference.py</strong>: load the trained model and inference the input data by the model.</li>
</ul>
</div>
<div class="section" id="dataset">
<h2>Dataset<a class="headerlink" href="#dataset" title="Permalink to this headline">¶</a></h2>
<p>The expected dataset is a CSV file with 2 columns. the first column
contains the Noun-Phrase string (a Noun-Phrase containing 2 words), and
the second column contains the correct label (if the 2 word Noun-Phrase
is a collocation - the label is 1, else 0)</p>
<p>If you wish to use an existing dataset for training the model, you can
download Tratz 2011 et al. dataset <a class="footnote-reference" href="#id5" id="id1">[1]</a> <a class="footnote-reference" href="#id6" id="id2">[2]</a> <a class="footnote-reference" href="#id7" id="id3">[3]</a> <a class="footnote-reference" href="#id8" id="id4">[4]</a> from the following link: <a class="reference external" href="https://vered1986.github.io/papers/Tratz2011_Dataset.tar.gz">Tratz
2011
Dataset</a>.
Is also available in
<a class="reference external" href="https://www.isi.edu/publications/licensed-sw/fanseparser/index.html">here</a>.
(The terms and conditions of the data set license apply. Intel does not
grant any rights to the data files or database.</p>
<p>After downloading and unzipping the dataset, run
<code class="docutils literal notranslate"><span class="pre">preprocess_tratz2011.py</span></code> in order to construct the labeled data and
save it in a CSV file (as expected for the model). The scripts read 2
.tsv files (‘tratz2011_coarse_grained_random/train.tsv’ and
‘tratz2011_coarse_grained_random/val.tsv’) and outputs 2 .csv files
accordingly to the same location.</p>
<p>Quick example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">examples</span><span class="o">/</span><span class="n">np_semantic_segmentation</span><span class="o">/</span><span class="n">preprocess_tratz2011</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">data</span> <span class="n">path_to_Tratz_2011_dataset_folder</span>
</pre></div>
</div>
<div class="section" id="pre-processing-the-data">
<h3>Pre-processing the data<a class="headerlink" href="#pre-processing-the-data" title="Permalink to this headline">¶</a></h3>
<p>A feature vector is extracted from each Noun-Phrase string using the
command <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">data.py</span></code></p>
<ul class="simple">
<li>Word2Vec word embedding (300 size vector for each word in the
Noun-Phrase) .<ul>
<li>Pre-trained Google News Word2vec model can download
<a class="reference external" href="https://drive.google.com/file/d/0B7XkCwpI5KDYNlNUTTlSS21pQmM/edit?usp=sharing">here</a></li>
<li>The terms and conditions of the data set license apply. Intel does
not grant any rights to the data files or database.</li>
</ul>
</li>
<li>Cosine distance between 2 words in the Noun-Phrase.</li>
<li>NLTKCollocations score (PMI score (from Manning and Schutze 5.4) and Chi-square score (Manning and Schutze 5.3.3)).</li>
<li>A binary features whether the Noun-Phrase has existing entity in
Wikidata.</li>
<li>A binary features whether the Noun-Phrase has existing entity in
WordNet.</li>
</ul>
<p>Quick example:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">data</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">data</span> <span class="n">input_data_path</span><span class="o">.</span><span class="n">csv</span> <span class="o">--</span><span class="n">output</span> <span class="n">prepared_data_path</span><span class="o">.</span><span class="n">csv</span> <span class="o">--</span><span class="n">w2v_path</span> <span class="o">&lt;</span><span class="n">path_to_w2v</span><span class="o">&gt;/</span><span class="n">GoogleNews</span><span class="o">-</span><span class="n">vectors</span><span class="o">-</span><span class="n">negative300</span><span class="o">.</span><span class="n">bin</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="running-modalities">
<h2>Running Modalities<a class="headerlink" href="#running-modalities" title="Permalink to this headline">¶</a></h2>
<div class="section" id="training">
<h3>Training<a class="headerlink" href="#training" title="Permalink to this headline">¶</a></h3>
<p>The command <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">examples/np_semantic_segmentation/train.py</span></code> will train the MLP classifier and
evaluate it. After training is done, the model is saved automatically:</p>
<p>Quick example:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">examples</span><span class="o">/</span><span class="n">np_semantic_segmentation</span><span class="o">/</span><span class="n">train</span><span class="o">.</span><span class="n">py</span> \
  <span class="o">--</span><span class="n">data</span> <span class="n">prepared_data_path</span><span class="o">.</span><span class="n">csv</span> \
  <span class="o">--</span><span class="n">model_path</span> <span class="n">np_semantic_segmentation_path</span><span class="o">.</span><span class="n">h5</span>
</pre></div>
</div>
</div>
<div class="section" id="inference">
<h3>Inference<a class="headerlink" href="#inference" title="Permalink to this headline">¶</a></h3>
<p>In order to run inference you need to have pre-trained
<code class="docutils literal notranslate"><span class="pre">&lt;model_name&gt;.h5</span></code> &amp; <code class="docutils literal notranslate"><span class="pre">&lt;model_name&gt;.json</span></code> files and data CSV file that was generated by
<code class="docutils literal notranslate"><span class="pre">prepare_data.py</span></code>. The result of <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">inference.py</span></code> is a CSV
file, each row contains the model’s inference in respect to the input
data.</p>
<p>Quick example:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">examples</span><span class="o">/</span><span class="n">np_semantic_segmentation</span><span class="o">/</span><span class="n">inference</span><span class="o">.</span><span class="n">py</span> \
  <span class="o">--</span><span class="n">model</span> <span class="n">np_semantic_segmentation_path</span><span class="o">.</span><span class="n">h5</span> \
  <span class="o">--</span><span class="n">data</span> <span class="n">prepared_data_path</span><span class="o">.</span><span class="n">csv</span> \
  <span class="o">--</span><span class="n">output</span> <span class="n">inference_data</span><span class="o">.</span><span class="n">csv</span> \
  <span class="o">--</span><span class="n">print_stats</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<table class="docutils footnote" frame="void" id="id5" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Stephen Tratz and Eduard Hovy. 2011. A Fast, Accurate, Non-Projective, Semantically-Enriched Parser. In Proceedings of the 2011 Conference on Empirical Methods in Natural Language Processing. Edinburgh, Scotland, UK.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>Dirk Hovy, Stephen Tratz, and Eduard Hovy. 2010. What’s in a Preposition? Dimensions of Sense Disambiguation for an Interesting Word Class. In Proceedings of COLING 2010: Poster Volume. Beijing, China.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id7" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td>Stephen Tratz and Dirk Hovy. 2009. Disambiguation of Preposition Sense using Linguistically Motivated Features. In Proceedings of Human Language Technologies: The 2009 Annual Conference of the North American Chapter of the Association for Computational Linguistics, Companion Volume: Student Research Workshop and Doctoral Consortium. Boulder, Colorado.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id8" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id4">[4]</a></td><td>Stephen Tratz and Eduard Hovy. 2010. A Taxonomy, Dataset, and Classifier for Automatic Noun Compound Interpretation. In Proceedings of the 48th Annual Meeting of the Association for Computational Linguistics. Uppsala, Sweden</td></tr>
</tbody>
</table>
</div>
</div>


           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>